//
//  HomeViewController.swift
//  Inpro
//
//  Created by 彭灿 on 16/9/13.
//  Copyright © 2016年 Roble. All rights reserved.
//

import UIKit


private let cellID = "cellid"

class HomeViewController: MainBaseViewController {
    
    public lazy var listViewModel = WBStatusListViewModel()
    
    override func loadData() {
        
        listViewModel.loadStatus(pullup: self.isPullup) { (isSuccess) in
            
            // 刷新数据完成
            print("刷新表格")
            // 结束刷新空间
            self.refreshControl?.endRefreshing()
            
            // 恢复上拉刷新标记
            self.isPullup = false
            
            // 刷新表格
            self.tableView?.reloadData()

            
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
//        view.backgroundColor = UIColor.black
        
    }
    
    @objc public func showFriends() {
        print(#function)
        let vc = DemoViewController()
        
        // 隐藏底部
        vc.hidesBottomBarWhenPushed = true
        
        navigationController?.pushViewController(vc, animated: true)
        
    }
    
}

// MARK: - 表格数据源方法
extension HomeViewController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return listViewModel.statusList.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        // 1.取 cell
        let cell = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath)
        // 2.设置cell
        cell.textLabel?.text = listViewModel.statusList[indexPath.row].text
        // 3.返回cell
        return cell
    }
}

// MARK: - 设置界面
extension HomeViewController {
    
    override func setupTableView() {
        super.setupTableView()
        
        // 设置导航栏按钮
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        
        // 注册原型 cell
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellID)
    }
    
}
